package com.lujuncheng.tankgame;

import java.io.Serializable;

/**
 * @author LuJuncheng
 * @version 1.0
 * 子弹类
 */
public class Shot implements Runnable, Serializable {
    int x;
    int y;
    int direct=0;
    int speed=2;
    boolean isLive=true;

    public Shot(int x, int y, int direct) {
        this.x = x;
        this.y = y;
        this.direct = direct;
    }

    /**
     * 启动此线程子弹运动
     */
    @Override
    public void run() {
        while (true){
            switch (direct){//射击
                case 0://向上
                    y-=speed;
                    break;
                case 1://向右
                    x+=speed;
                    break;
                case 2://向下
                    y+=speed;
                    break;
                case 3://向左
                    x-=speed;
                    break;
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (!(x>=0&&x<=1000&&y>=0&&y<=750&&isLive)){
                //System.out.println("子弹线程退出");
                isLive=false;
                break;
            }
        }
    }
}
